package com.raycloud.interceptor;

import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.raycloud.domain.User;

public class SessionUserInterceptor extends AbstractInterceptor{

	/**
	 * 
	 */
	private static final long serialVersionUID = 4645827411296557985L;

	@SuppressWarnings("unchecked")
	public String intercept(ActionInvocation ai) throws Exception {
		ActionContext actionContext = ai.getInvocationContext();
		Map<String, Object> sessionMap = actionContext.getSession();
		User user = (User) sessionMap.get("user");
		if(user == null) {
			HttpServletResponse rsp = ServletActionContext.getResponse();
			rsp.sendRedirect("/login.do");
			return null;
		}
		return ai.invoke();
	}

}
